# Author: mosra <mosra@centrum.cz>
pkgname=magnum-integration
pkgver=dev
pkgrel=1
pkgdesc="Integration libraries for the Magnum C++11/C++14 graphics engine"
arch=('i686' 'x86_64')
url="https://magnum.graphics"
license=('MIT')
depends=('magnum' 'bullet' 'eigen' 'glm' 'imgui-src')
makedepends=('cmake' 'ninja')
options=('!strip' '!buildflags')
provides=('magnum-integration-git')

_rootdir=$startdir/../../

_buildtype=Release
# _buildtype=RelWithDebInfo

build() {
    mkdir -p "$_rootdir/build"
    cd "$_rootdir/build"

    # Colored output is enabled implicitly. If Ninja detects it's outputting to
    # a pipe, it strips it away from the output, alternatively you can set the
    # GCC_COLORS= (empty) env variable to temporarily disable colors. The
    # inverse, i.e. preserving colors when Ninja outputs to a pipe can be done
    # with CLICOLOR_FORCE=1: https://github.com/ninja-build/ninja/issues/2196
    cmake .. \
        -DCMAKE_CONFIGURATION_TYPES="Debug;Release;RelWidthDebInfo" \
        -DCMAKE_CROSS_CONFIGS=all \
        -DCMAKE_CXX_FLAGS_DEBUG="-g -gz=zstd" \
        -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -fno-omit-frame-pointer -gz=zstd" \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_COLOR_DIAGNOSTICS=ON \
        -DIMGUI_DIR=/opt/imgui \
        -DMAGNUM_WITH_BULLET=ON \
        -DMAGNUM_WITH_DART=OFF \
        -DMAGNUM_WITH_EIGEN=ON \
        -DMAGNUM_WITH_GLM=ON \
        -DMAGNUM_WITH_IMGUI=ON \
        -DMAGNUM_BUILD_TESTS=ON \
        -DMAGNUM_BUILD_GL_TESTS=ON \
        -G "Ninja Multi-Config"
    ninja all:Debug all:$_buildtype
}

check() {
    cd "$_rootdir/build"
    export CORRADE_TEST_SKIP_BENCHMARKS=ON
    export CORRADE_TEST_COLOR=ON

    for config in Debug $_buildtype; do
        ctest -C $config --output-on-failure -j
        MAGNUM_DISABLE_EXTENSIONS="GL_ARB_draw_elements_base_vertex" ctest -C $config --output-on-failure -j -R GLTest
    done
}

package() {
    cd "$_rootdir/build"
    DESTDIR="$pkgdir/" ninja install:Debug

    if [ "$_buildtype" = RelWithDebInfo ]; then
        DESTDIR="$pkgdir/" ninja install:$_buildtype
    else
        DESTDIR="$pkgdir/" ninja install/strip:$_buildtype
    fi
}
